{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑轮播图</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">
                        <input type="hidden" name="id" value="{$info.lb_id}">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="lb_name"  value="{$info.lb_name}" lay-verify="required" placeholder="名称" class="layui-input ">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">单图片上传：</label>
                            <input type="hidden" name="img" id="lay-img" lay-verify="image" value="{$info.lb_image}">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                        <img class="layui-append-img" src="{$info.lb_image}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group" id="lun">
                            <label class="layui-form-label">类型：</label>
                            <div class="layui-input-block">
                                <select name="type" lay-filter="lun">
                                    <option value="1" {$info.lb_type==1?'selected':''>首页轮播图</option>
                                    <option value="2" {$info.lb_type==1?'selected':''>我的界面背景图</option>
                                </select>
                            </div>
                        </div>

                        {if $info.lb_type == 1}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group" id="lb_where">
                            <label class="layui-form-label">使用类型：</label>
                            <div class="layui-input-block">
                                <select id="aaaaaa" name="lb_where" xm-select-radio="" lay-filter="role">
                                    <option value="1" {$info.lb_where==1?'selected':''>房源</option>
                                    <option value="2" {$info.lb_where==2?'selected':''>经纪人列表</option>
                                    <option value="3" {$info.lb_where==3?'selected':''>装修公司</option>
                                    <!--<option value="4" >外链</option>-->
                                </select>
                            </div>
                        </div>
                        {/if}

                        {if $info.lb_where == 1}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" id="house_id">
                            <label class="layui-form-label">选择房源：</label>
                            <div class="layui-input-block">
                                <select name="house_id" xm-select="select1" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    <option value="" >请选择</option>
                                    {foreach name="house" item="v"}
                                    <option value="{$v.h_id}" {$info.lb_content==$v.h_id?'selected':''}>{$v.h_title}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {/if}

                        {if $info.lb_where == 3}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" id="company_id" style="display: none">
                            <label class="layui-form-label">选择装修公司：</label>
                            <div class="layui-input-block">
                                <select name="company_id" xm-select="select2" xm-select-search="" xm-select-radio="" xm-select-search-type="dl">
                                    <option value="" >请选择</option>
                                    {foreach name="company" item="vo"}
                                    <option value="{$vo.id}" {$info.lb_content==$vo.id?'selected':''}>{$vo.name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {/if}

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8" id="wailian" style="display: none">
                            <label class="layui-form-label">外链：</label>
                            <div class="layui-input-block">
                                <input type="text" name="lb_wailian" placeholder="外链" class="layui-input ">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var editor = wk.wang({elem:'#LAY_editor'});
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.verify({
            image:[/\S/,'请上传图片'],
            editor:function(value,item){
                if(editor.txt.html() == '<p><br></p>'){
                    return '请填写内容';
                }
            }
        });
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            data.field.content = editor.txt.html();
            $.ajax({
                url:"{:url('edit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Banner/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
    });
</script>
</body>
</html>
